<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <div>
            <span>用户名：</span>
            <span>
        <input type="text" v-model='uname'>
      </span>
            <span style="color:red" v-show="error">长度不足</span>
            <span style="color:blue" v-show="!error">符合要求</span>
        </div>
    </div>
    <script type="text/javascript" src="js/vue.js"></script>
    <script type="text/javascript">
        /*      
                                                              侦听器
                                                              1、实时监听用户名的输入长度, 如果长度小于6的话, 提示用户长度不足, 否则提示 符合要求
                                                            */
        var vm = new Vue({
            el: '#app',
            data: {
                uname: '',
                error: true
            },
            methods: {},
            watch: {
                uname: function() {
                    if (this.uname.length < 6) {
                        this.error = true
                    } else {
                        this.error = false
                    }
                }
            }
        });
    </script>
</body>

</html>